﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.SessionState;
using WorkSummary.Bussiness.Bll;
using WorkSummary.Common;

namespace WorkSummaryReoprter.ashx
{
    /// <summary>
    /// Common 的摘要说明
    /// </summary>
    public class Common : IHttpHandler, IRequiresSessionState
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            var action = context.Request["action"];
            switch (action)
            {
                case "GetUsers":
                    context.Response.Write(JSONhelper.ToJson(BUser.Instance.GetAllUser()));
                    break;
                case "GetChartData":
                    context.Response.Write(JSONhelper.ToJson(BTask.Instance.GetChartData()));
                    break;
                case "GetChartDataWithDate":
                    var sDate = context.Request["sDate"];
                    var eDate = context.Request["eDate"];
                    context.Response.Write(JSONhelper.ToJson(BTask.Instance.GetChartDataWithDate(sDate, eDate)));
                    break;
                case "GetPieDataByUser":
                    var userid = context.Request["userid"];
                    context.Response.Write(JSONhelper.ToJson(BTask.Instance.GetPieDataByUser(userid)));
                    break;
                default:
                    context.Response.Write(JSONhelper.ToJson(new { code = -1, msg = "no action matched！" }));
                    break;
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}